package ruanjian2101.web.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import ruanjian2101.domain.User;
import ruanjian2101.service.UserService;
import ruanjian2101.service.impl.UserServicelmpl;

import java.io.IOException;
import java.util.List;
@WebServlet("/userListServlet")
public class UserListServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*1.调用service层 UserService 完成查询*/
        UserService userService=new UserServicelmpl();
        List<User> users = userService.findAll();
        req.setAttribute("users",users);
        req.getRequestDispatcher("/list.jsp").forward(req,resp);
    }
}
